#Transfer the original training data provided by JRS organization.
#The input may contain lots of zero values. To improve the I/O time,
#we eliminate the input to be as the form:
#AttrID:Value AttrID:Value ...
#-ktchuang
import sys

if len(sys.argv) <= 2:
    print('Usage: python {0} LongInputFile EliminateOutputFile '.format(sys.argv[0]))
    raise SystemExit

print('Transfer ' + sys.argv[1] + ' to '+ sys.argv[2])
inf = open(sys.argv[1])

outf = open(sys.argv[2],'w')
lines = inf.readlines()
for line in lines:    
    attrs = line.split()
    num=len(attrs)
    start=0
    for x in range(num):
        if int(attrs[x])!=0:
            if start == 0:
                outf.write('1')
                start=1
            else:
                outf.write(',1')
        else:
            if start == 0:
                outf.write('0')
                start=1
            else:
                outf.write(',0')
    outf.write('\n');        
inf.close();
outf.close();